package metrics;

import java.util.Vector;

public class PRStatistic {
	
	protected int currentRank = 1;
	protected Vector<Entry> entries;
	
	protected class Entry {
		private int rank;
		private  float currentRecall;
		private float currentPrecision;
		
		
		
		public Entry(int rank, float currentRecall, float currentPrecision) {
			super();
			this.rank = rank;
			this.currentRecall = currentRecall;
			this.currentPrecision = currentPrecision;
		}
		
		public int getRank() {
			return rank;
		}
		public float getCurrentRecall() {
			return currentRecall;
		}
		public float getCurrentPrecision() {
			return currentPrecision;
		}	
	}
	
	public PRStatistic() {
		entries = new Vector<Entry>();
	}
	
	public float getPrecisionOfEntry(int index) {
		return entries.get(index).getCurrentPrecision();
	}
	
	public void addEntry(float recall, float Precision) {
		Entry e = new Entry(currentRank++, recall, Precision);
		entries.add(e);
	}
	
	public NormalizedPRStatictic getNormalizedVersion() {
		NormalizedPRStatictic normalized = new NormalizedPRStatictic();
		for (int i = 0; i<= NormalizedPRStatictic.NORMALIZAION_PRECISION; i++) {
			float recall = i*((float)1/NormalizedPRStatictic.NORMALIZAION_PRECISION); 
			float precision=0;
			for (Entry e : entries) {
				if(e.getCurrentRecall()>=recall && e.getCurrentPrecision()>precision) {
					precision = e.getCurrentPrecision();
				}
			}
			normalized.addEntry(recall, precision);
			}
		return normalized;
	}

	public void showStatistics() {
		for (Entry e : entries) {
			System.out.println(e.getRank() + "  " + "recall:" + e.getCurrentRecall() + "  " + e.getCurrentPrecision());
		}
		System.out.println("*************************************");
	}
	
}
